/*
 * Grid represents the 2D game world.
 * Grid contains a 2D array of ArrayLists. 
 * Each ArrayList contains 0 or more GridObjects.
 */

package ShardSystem;

import java.util.ArrayList;

public class Grid {
    
    private ArrayList[][] grid;;
    
    public Grid(int x, int y) {
        this.grid = new ArrayList[x][y];
        for(int i = 0; i < x; i ++) {
            for(int j = 0; j < y; j++) {
                grid[i][j] = new ArrayList<GridObject>();
            }
        }
    }

    public void addToGrid(int x, int y, GridObject newObject) {
        try {
             this.grid[x][y].add(newObject);
        } catch(Exception e) {
            System.out.println("Failed to add object " + newObject.toString() + " to grid at " + x + ", " + y + ".");
            System.exit(1);
        }
    }

    /**
     * @return the grid
     */
    public ArrayList[][] getGrid() { return grid; }

    /**
     * @param grid the grid to set
     */
    public void setGrid(ArrayList[][] grid) { this.grid = grid; }


    
}
